package com.lb.uts.annotation;

import com.lb.uts.constants.UTSConstants;
import com.lb.uts.entity.ActiveScheduling;
import com.lb.uts.service.IActiveSchedulingService;
import com.lb.uts.service.manager.ModifyManager;
import com.lb.uts.util.RscHttpUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 描述：完成业务逻辑后，通知后台线程，刷新缓存数据
 * 作者：liangb
 * 日期：2018/11/2
 * 时间：10:03
 */
@Aspect
@Component
public class ModifyAop {
    private final static Logger logger = LoggerFactory.getLogger(ModifyAop.class);

    @Autowired
    private IActiveSchedulingService activeSchedulingService;

    private final static String modify_url = "/jobInfo/modify";

    @Around("@annotation(com.lb.uts.annotation.Modify)")
    public Object aroundMethod(ProceedingJoinPoint pjd) throws Throwable {
        Object obj = pjd.proceed();
        ModifyManager.addEmpty();
        //通知其他系统刷新数据
        List<ActiveScheduling> activeSchedulingList = activeSchedulingService.queryByEntity(new ActiveScheduling());
        for (ActiveScheduling activeScheduling : activeSchedulingList) {
            //不用通知自己
            String ip = activeScheduling.getIp();
            if (!ip.equals(UTSConstants.LOCAL_IP_PORT)) {
                RscHttpUtils.get(ip + modify_url, null, 10000, "");
            }
        }
        return obj;
    }

}
